const app = getApp()
Page({
  data: {
    basicInformationArr: [
      { label: '身高', con: '' },
      { label: '体重', con: '' },
      { label: '籍贯', con: '' },
      { label: '月薪', con: '' },
      { label: '职业', con: '' },
      { label: '学历', con: '' },
      { label: '婚姻状况', con: '' },
      { label: '所在地区', con: '' }
    ],
    detailedInformationArr: [
      { label: '民族', con: '' },
      { label: '生肖', con: '' },
      { label: '星座', con: '' },
      { label: '血型', con: '' },
      { label: '有无子女', con: '' },
      { label: '购车情况', con: '' },
      { label: '住房情况', con: '' }
    ],
    mainInfo: {},
    labels: []
  },
  onUnload:function(){
    wx.setStorageSync('sayHiContent', null);
    wx.setStorageSync('mateid', null);
    wx.setStorageSync('msgContent', null);
  },
  onReady: function () {
    this.hiDialog = this.selectComponent('#hiDialog');
    this.msgDialog = this.selectComponent('#msgDialog');
  },
  onLoad: function (opt) {
    var _this = this;
    wx.setNavigationBarTitle({
      title: '会员详情',
    });
    this.initPage(opt)
  },
  initPage: function (opt) {
    var _this = this;
    var userid = app.globalData.userid
    wx.setStorageSync('mateid', opt.userid)
    app.doReq(app.globalData.SERVICE.MATES.DETAILS, { id: opt.userid, 'xgmember.id': userid }, "GET", function (res) {
      _this.setData({
        mainInfo: res.data.obj,
        labels: res.data.obj.detail.labels.split(','),
        basicInformationArr: [
          { label: '身高', con: res.data.obj.member.height },
          { label: '体重', con: res.data.obj.member.weight },
          { label: '籍贯', con: res.data.obj.member.nativePlaces },
          { label: '月薪', con: res.data.obj.member.moneys },
          { label: '职业', con: res.data.obj.member.zys },
          { label: '学历', con: res.data.obj.member.educations },
          { label: '婚姻状况', con: res.data.obj.member.marrys },
          { label: '所在地区', con: res.data.obj.member.cregion.name + res.data.obj.member.xregion.name }
        ],
        detailedInformationArr: [
          { label: '民族', con: res.data.obj.member.nations },
          { label: '生肖', con: res.data.obj.member.zodiacs },
          { label: '星座', con: res.data.obj.member.constellations },
          { label: '血型', con: res.data.obj.member.bloods },
          { label: '有无子女', con: res.data.obj.member.childrens },
          { label: '购车情况', con: res.data.obj.member.cars },
          { label: '住房情况', con: res.data.obj.member.rooms }
        ],
      });
      if (res.data.obj.detail.labels.split(',') > 0) {
        _this.setData({
          labels: res.data.obj.detail.labels.split(',')
        });
      }
    })
  },
  attention: function (e) {
    var _this = this;
    var mateid = e.currentTarget.dataset.mateid;
    var userInfo = wx.getStorageSync('userInfo');
    var userId = app.globalData.userid;
    if (userId == mateid) {
      wx.showModal({
        title: '提示',
        content: '不能关注自己哦',
      })
    } else {
      app.doReq(app.globalData.SERVICE.MATES.VERIFY, { id: userId }, 'GET', function (res) {

        if (res.data.errmsg.indexOf("择偶") > 0) {
          // 择偶条件没有完善跳转到择偶条件
          app.confirm("提示", "为更好地为您提供服务，请在“个人编辑”中完善择偶条件。").then(function (value) {
            if (value) {
              location.href = 'uc_mate_condition.html';
            }
          });
        } else if (res.data.errmsg.indexOf("基本信息") > 0) {
          app.confirm("提示", "为更好地为您提供服务，请在“个人编辑”中完善个人资料。").then(function (value) {
            if (value) {
              location.href = 'uc_profile.html';
            }
          });
        } else if (res.data.errmsg.indexOf("形象照") > 0) {
          app.confirm("提示", "为更好地为您提供服务，请在“个人编辑”中上传形象照。").then(function (value) {
            if (value) {
              location.href = 'uc_basicInfo.html';
            }
          });
        } else {
          app.doReq(app.globalData.SERVICE.MATES.ATTENTION, { 'cern.memberA.id': userId, 'cern.memberB.id': mateid, 'cern.type': 2 }, 'GET', function (res) {

            if (res.data.code == 200) {
              wx.showToast({
                title: '关注成功',
                icon: 'success'
              });
              _this.setData({
                'mainInfo.member.sfgz': 1
              });
            }
          });
        }
      });
    }
  },
  noAttention: function (e) {//取消关注
    var _this = this;
    var mateid = e.currentTarget.dataset.mateid;
    var userInfo = wx.getStorageSync('userInfo');
    var userId = app.globalData.userid;
    app.doReq(app.globalData.SERVICE.MATES.NOATTENTION, { 'xgmember.id': mateid, id: userId }, 'GET', function (res) {
      if (res.data.code == 200) {
        wx.showToast({
          title: '取消关注成功',
          icon: 'success'
        });
        _this.setData({
          'mainInfo.member.sfgz': 0
        });
      }
    });
  },
  sayhi: function () {
    this.hiDialog.show()
  },
  sendMsg(){
    this.msgDialog.show();
  },
})